using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
namespace LdExpress
{
    public class LocalCosts
    {
        //CIC	Seal BL telex ENS EBS/TEU Remark EBS	LATE PAY MENT FEE

        public long ID = -1;
        public string Carr = "";
        public string Import20DC = "";
        public string Import40DC = "";
        public string ImportHC40 = "";
        public string Import20RF = "";
        public string Import40RF = "";
        public string Export20DC = "";
        public string Export40DC = "";
        public string ExportHC40 = "";
        public string Export20RF = "";
        public string Export40RF = "";
        public string CIC = "";
        public string Seal = "";
        public string BL = "";
        public string Telex = "";
        public string ENS = "";
        public string EBS_TEU = "";
        public string Description = "";
        public string Remark = "";
        public string LatePayMentFEE = "";
        public int Sort = 0;
        public string VSCont = "";
        public DateTime LastUpdate = DateTime.Now;

        public LocalCosts()
        {
        }

        public LocalCosts(long lID)
        {
            this.ID = lID;
        }

        public void Save(MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            string strTableName = "tbl_localcosts";

            if (ID <= 0) // new object, we insert new record to database
            {
                //ID = long.Parse(DBModule.GetNewID(typeof(Bill), "tbl_bill" , "ID", "ID", cn, trans));
                strSQL = "Insert into " + strTableName + " (" +
                    "`Carr`" +
                             ",`Import20DC`" +
                             ",`Import40DC`" +
                             ",`ImportHC40`" +
                             ",`Import20RF`" +
                             ",`Import40RF`" +
                             ",`Export20DC`" +
                             ",`Export40DC`" +
                             ",`ExportHC40`" +
                             ",`Export20RF`" +
                             ",`Export40RF`" +
                             ",`CIC`" +
                             ",`Seal`" +
                             ",`BL`" +
                             ",`Telex`" +
                             ",`ENS`" +
                             ",`EBS_TEU`" +
                             ",`Description`" +
                             ",`Remark`" +
                             ",`LatePayMentFEE`" +
                             ",`Sort`" +
                             ",`VSCont`" +
                             ",`LastUpdate`" +
                             ") " +
                         " values(" +
                         "'" + DBModule.RefineString(Carr) + "'" +
                             ",'" + DBModule.RefineString(Import20DC) + "'" +
                             "," + "'" + DBModule.RefineString(Import40DC) + "'" +
                             "," + "'" + DBModule.RefineString(ImportHC40) + "'" +
                             "," + "'" + DBModule.RefineString(Import20RF) + "'" +
                             "," + "'" + DBModule.RefineString(Import40RF) + "'" +
                             ",'" + DBModule.RefineString(Export20DC) + "'" +
                             "," + "'" + DBModule.RefineString(Export40DC) + "'" +
                             "," + "'" + DBModule.RefineString(ExportHC40) + "'" +
                             "," + "'" + DBModule.RefineString(Export20RF) + "'" +
                             "," + "'" + DBModule.RefineString(Export40RF) + "'" +
                             "," + "'" + DBModule.RefineString(CIC) + "'" +
                             "," + "'" + DBModule.RefineString(Seal) + "'" +
                             "," + "'" + DBModule.RefineString(BL) + "'" +
                             "," + "'" + DBModule.RefineString(Telex) + "'" +
                             "," + "'" + DBModule.RefineString(ENS) + "'" +
                             "," + "'" + DBModule.RefineString(EBS_TEU) + "'" +
                             "," + "'" + DBModule.RefineString(Description) + "'" +
                             "," + "'" + Remark.ToString() + "'" +
                             "," + "'" + LatePayMentFEE.ToString() + "'" +
                             "," + Sort.ToString() +
                             "," + "'" + DBModule.RefineString(VSCont) + "'" +
                             "," + DBModule.RefineDatetime(LastUpdate) +
                             ")";
                // run SQL statement
                //throw new Exception(strSQL);
                DBModule.ExecuteNonQuery(strSQL, cn, trans);
                UserObjectsLog.SaveObjectActionLog("LocalCosts", "add", cn, trans);
                //GV.Response.Write(strSQL);
            }
            else // edit object, we EBS_TEU old record in database
            {
                // build SQL statement
                strSQL = "Update " + strTableName + " set " +
                    "Carr='" + DBModule.RefineString(Carr) + "'" +
                            ",Import20DC='" + DBModule.RefineString(Import20DC) + "'" +
                             ",Import40DC='" + DBModule.RefineString(Import40DC) + "'" +
                             ",ImportHC40='" + DBModule.RefineString(ImportHC40) + "'" +
                             ",Import20RF='" + DBModule.RefineString(Import20RF) + "'" +
                             ",Import40RF='" + DBModule.RefineString(Import40RF) + "'" +
                             ",Export20DC='" + DBModule.RefineString(Export20DC) + "'" +
                             ",Export40DC='" + DBModule.RefineString(Export40DC) + "'" +
                             ",ExportHC40='" + DBModule.RefineString(ExportHC40) + "'" +
                             ",Export20RF='" + DBModule.RefineString(Export20RF) + "'" +
                             ",Export40RF='" + DBModule.RefineString(Export40RF) + "'" +
                             ",CIC='" + DBModule.RefineString(CIC) + "'" +
                             ",Seal='" + DBModule.RefineString(Seal) + "'" +
                             ",BL='" + DBModule.RefineString(BL) + "'" +
                             ",Telex='" + DBModule.RefineString(Telex) + "'" +
                             ",ENS='" + DBModule.RefineString(ENS) + "'" +
                             ",EBS_TEU='" + DBModule.RefineString(EBS_TEU) + "'" +
                             ",Description='" + DBModule.RefineString(Description) + "'" +
                             ",Remark = '" + Remark.ToString() + "'" +
                             ",LatePayMentFEE = '" + LatePayMentFEE.ToString() + "'" +
                             ",Sort = " + Sort.ToString() +
                             ",VSCont='" + DBModule.RefineString(VSCont) + "'" +
                             ",LastUpdate=" + DBModule.RefineDatetime(LastUpdate) + "" +
                    " where ID=" + ID.ToString();
                // run SQL statement
                DBModule.ExecuteNonQuery(strSQL, cn, trans);
                UserObjectsLog.SaveObjectActionLog("LocalCosts", "edit", cn, trans);
            }
        }
        public void Delete(MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "DELETE FROM tbl_localcosts WHERE ID = " + this.ID.ToString();
            DBModule.ExecuteNonQuery(strSQL, cn, trans);
            UserObjectsLog.SaveObjectActionLog("LocalCosts", "delete", cn, trans);
        }
        public void Load(MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "SELECT * FROM tbl_localcosts WHERE ID = " + ID.ToString() + " limit 0,1";
            DataSet ds = DBModule.ExecuteQuery(strSQL, cn, trans);
            //Fill data into this object
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                if (!dr.IsNull("ID")) ID = long.Parse(dr["ID"].ToString());
                if (!dr.IsNull("Carr")) Carr = dr["Carr"].ToString();
                if (!dr.IsNull("Import20DC")) Import20DC = dr["Import20DC"].ToString();
                if (!dr.IsNull("Import40DC")) Import40DC = dr["Import40DC"].ToString();
                if (!dr.IsNull("ImportHC40")) ImportHC40 = dr["ImportHC40"].ToString();
                if (!dr.IsNull("Import20RF")) Import20RF = dr["Import20RF"].ToString();
                if (!dr.IsNull("Import40RF")) Import40RF = dr["Import40RF"].ToString();
                if (!dr.IsNull("Export20DC")) Export20DC = dr["Export20DC"].ToString();
                if (!dr.IsNull("Export40DC")) Export40DC = dr["Export40DC"].ToString();
                if (!dr.IsNull("Export20RF")) Export20RF = dr["Export20RF"].ToString();
                if (!dr.IsNull("Export40RF")) Export40RF = dr["Export40RF"].ToString();
                if (!dr.IsNull("CIC")) CIC = dr["CIC"].ToString();
                if (!dr.IsNull("Seal")) Seal = dr["Seal"].ToString();
                if (!dr.IsNull("BL")) BL = dr["BL"].ToString();
                if (!dr.IsNull("Telex")) Telex = dr["Telex"].ToString();
                if (!dr.IsNull("ENS")) ENS = dr["ENS"].ToString();
                if (!dr.IsNull("EBS_TEU")) EBS_TEU = dr["EBS_TEU"].ToString();
                if (!dr.IsNull("Description")) Description = dr["Description"].ToString();
                if (!dr.IsNull("Remark")) Remark = dr["Remark"].ToString();
                if (!dr.IsNull("LatePayMentFEE")) LatePayMentFEE = dr["LatePayMentFEE"].ToString();
                if (!dr.IsNull("Sort")) Sort = int.Parse(dr["Sort"].ToString());
                if (!dr.IsNull("VSCont")) VSCont = dr["VSCont"].ToString();
                if (!dr.IsNull("LastUpdate")) LastUpdate = DateTime.Parse(dr["LastUpdate"].ToString());
            }
        }

        public static void GetList(string strIDs, string OrderBy, int NumOfItemsPerPage, int PageNo, out int NumberOfPages, out DataSet ds, MySqlConnection cn, MySqlTransaction trans)
        {
            NumberOfPages = 0;
            string strSQL = "";
            ds = null;
            // build SQL statement
            strSQL = "Select * from tbl_localcosts where 1=1 ";
            if ((strIDs != "") && (strIDs != null))
            {
                if (strIDs != "All")
                    strSQL += strIDs;
            }
            if ((OrderBy != null) && (OrderBy != ""))
                strSQL = strSQL + " Order By " + DBModule.RefineString(OrderBy);
            //GV.Response.Write("sql=" + strSQL);
            // run SQL statement
            if (NumOfItemsPerPage > 0)
            {
                ds = DBModule.ExecuteQuery(strSQL, NumOfItemsPerPage, PageNo, out NumberOfPages, cn, trans);
            }
            else
                ds = DBModule.ExecuteQuery(strSQL, cn, trans);

        }
        public void DoSearch(string strKeywords, string OrderBy, out DataSet ds, MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            ds = null;
            // build SQL statement
            strSQL = "Select `ID` from tbl_localcosts where 1=1 ";

            if ((OrderBy != null) && (OrderBy != ""))
                strSQL = strSQL + " Order By " + DBModule.RefineString(OrderBy);
            // run SQL statement
            ds = DBModule.ExecuteQuery(strSQL, cn, trans);
        }
    }
}
